//
//  SelectedCell.m
//  单选、多选
//
//  Created by lili on 16/8/23.
//  Copyright © 2016年 陈浩. All rights reserved.
//

#import "SelectedCell.h"
#define UIScreenW [UIScreen mainScreen].bounds.size.width
@implementation SelectedCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
  
    
}

+(instancetype)cellForTableView:(UITableView *)tableView{
    static NSString *ID = @"cell";
    SelectedCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
      cell  = [[SelectedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
      cell.selectionStyle = UITableViewCellSelectionStyleDefault;
    
    }
    return cell;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

-(instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"check_gray"]];
        self.accessoryView = imgView;


    }
    return self;
}

-(void)setIsSelected:(BOOL)isSelected{
    _isSelected = isSelected;
}


- (void)setIsAllSelected:(BOOL)isAllSelected{
    _isAllSelected = isAllSelected;
    _isSelected = _isAllSelected;
}



-(void)layoutSubviews{
    [super layoutSubviews];
    for (UIView *view in self.subviews){
        if ([view isKindOfClass:[UIImageView class]]) {
            UIImageView *imageView = (UIImageView *)view;
            if (_isSelected) {
               imageView.image = [UIImage imageNamed:@"checked_all"];
            }else{
                imageView.image = [UIImage imageNamed:@"check_gray"];
            }
        }

    }
}

@end
